/* GUI CONVERTED from rebkflnm.p (converter v1.75) Sat Aug 12 23:04:38 2000 */
/* rebkflnm.p - REPETITIVE                                                    */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/*F0PN*/ /*V8:ConvertMode=Maintenance                                         */
/*H1J5*/ /*V8:RunMode=Character,Windows                                       */
/* REVISION: 7.3      LAST MODIFIED: 10/31/94   BY: WUG *GN77*                */
/* REVISION: 7.3      LAST MODIFIED: 11/03/94   BY: WUG *GN98*                */
/* REVISION: 7.3      LAST MODIFIED: 07/15/96   BY: *G1ZY* Julie Milligan     */
/* REVISION: 8.6E     LAST MODIFIED: 08/17/98   BY: *H1J5* Dana Tunstall      */
/* REVISION: 9.0      LAST MODIFIED: 04/16/99   BY: *J2DG* Reetu Kapoor       */
/* REVISION: 9.1      LAST MODIFIED: 10/01/99   BY: *N014* Jeff Wootton       */
/* REVISION: 9.1      LAST MODIFIED: 10/25/99   BY: *N002* Bill Gates         */
/* REVISION: 9.1      LAST MODIFIED: 11/17/99   BY: *N04H* Vivek Gogte        */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KP* myb                */

/*J2DG*/ /* GROUPED MULTIPLE FIELD ASSIGNMENTS INTO ONE AND ADDED NO-UNDO */
/*J2DG*/ /* WHEREVER MISSING AND REPLACED FIND STATEMENTS WITH FOR FIRST  */
/*J2DG*/ /* STATEMENTS FOR ORACLE PERFORMANCE.                            */

/* SUBPROGRAM TO BACKFLUSH NONMILESTONES                                      */

         {mfdeclre.i}

         define input parameter cumwo_lot  as character no-undo.
         define input parameter op         as integer   no-undo.
         define input parameter eff_date   as date      no-undo.
         define input parameter shift      as character no-undo.
         define input parameter trans_type as character no-undo.
/*G1ZY*         define input param qty_proc as integer. */
/*G1ZY*/ define input parameter qty_proc   as decimal   no-undo.

         define buffer next_wr_route for wr_route.
         define variable batchqty          as integer   no-undo.
         define variable bom_code          as character no-undo.
         define variable dept              as character no-undo.
         define variable earn_code         as character no-undo.
         define variable extd_std_lbr_hours as decimal  no-undo.
         define variable ophist_recid      as recid     no-undo.
         define variable rejected          like mfc_logical no-undo.
         define variable following_op_input_que as decimal  no-undo.
/*H1J5*/ define variable mfc-recid         as recid         no-undo.

         define workfile work_route
            field work_op as integer
            field work_qty_to_process as decimal
            field work_qty_to_move_next_op as decimal.

/*N04H** {rewrsdef.i}                                                         */

/*H1J5*/ for each work_route exclusive-lock:
/*H1J5*/     delete work_route.
/*H1J5*/ end.

/*H1J5*/ /* BEGIN OF ADDED CODE */
         if can-find(mfc_ctrl where mfc_field = "rpc_zero_bal_wip")
         then do:
            for first mfc_ctrl
                fields (mfc_char mfc_field mfc_label mfc_logical
                mfc_module mfc_seq mfc_type)
                where mfc_field = "rpc_zero_bal_wip" no-lock:
            end.
         end.
         else do:
            {gprun.i ""remfccr.p"" "(output mfc-recid)"}
/*GUI*/ if global-beam-me-up then undo, leave.

            for first mfc_ctrl
                fields (mfc_char mfc_field mfc_label mfc_logical
                mfc_module mfc_seq mfc_type)
                where recid(mfc_ctrl) = mfc-recid no-lock:
            end.
         end.
/*H1J5*/ /* END OF ADDED CODE */

/*N002*/ /*H1J5 MADE REBKFLNM.P DO THE BACKFLUSH OF THE OPERATION BEING
/*N002*/ REPORTED, WHEN IN FACT IT SHOULD HAVE ONLY BEEN BACKFLUSHING
/*N002*/ PRIOR NONMILESTONE OPERATIONS.
/*N002*/
/*N002*/ DO NOT PROCESS PRIOR NONMILESTONES IF PULL WIP LOGIC
/*N002*/ IS ENABLED BUT QTY TO PROCESS IS < 0.*/
/*N002*/
/*N002*/ if available mfc_ctrl and mfc_logical = no
/*N002*/ and qty_proc < 0 then leave.

/*J2DG** find wo_mstr where wo_lot = cumwo_lot no-lock. */
/*J2DG** find wr_route where wr_lot = cumwo_lot and wr_op = op no-lock. */

/*J2DG*/ for first wo_mstr
/*N014*     BEGIN DELETE
 *J2DG*     fields (wo_acct wo_cc wo_line wo_lot wo_mtl_var wo_mvrr_acct
 *J2DG*             wo_mvrr_cc wo_nbr wo_part wo_project wo_site
 *J2DG*             wo_so_job wo_vend wo_wip_tot)
 *N014*     END DELETE */
/*N014*/    fields (wo_line wo_lot wo_mtl_var
/*N014*/            wo_nbr wo_part wo_project wo_site
/*N014*/            wo_so_job wo_vend wo_wip_tot)
/*J2DG*/    where wo_lot = cumwo_lot no-lock:
/*J2DG*/ end. /* FOR FIRST WO_MSTR */

/*J2DG*/ for first wr_route
/*J2DG*/    fields (wr_auto_lbr wr_lot wr_mch wr_milestone wr_op
/*J2DG*/            wr_qty_inque wr_qty_outque wr_run wr_wkctr)
/*J2DG*/    where wr_lot = cumwo_lot
/*J2DG*/      and wr_op  = op no-lock:
/*J2DG*/ end. /* FOR FIRST WR_ROUTE */

         do trans.

/*N04H**    {rewrsget.i &lot=wr_lot &op=wr_op}                                */

            following_op_input_que = wr_qty_inque - qty_proc.
         end.


/*H1J5*/ if (available mfc_ctrl and mfc_logical = yes) then do:

         /*GET LIST OF OPS TO BACKFLUSH*/
         for each wr_route
/*J2DG*/    fields (wr_auto_lbr wr_lot wr_mch wr_milestone wr_op
/*J2DG*/            wr_qty_inque wr_qty_outque wr_run wr_wkctr)
        no-lock where wr_lot = cumwo_lot and wr_op < op
            while not wr_milestone
            by wr_lot descending by wr_op descending:

/*N04H** BEGIN DELETE SECTION
 *          do trans:
 *             {rewrsget.i &lot=wr_lot &op=wr_op}
 *          end.
 *N04H** END DELETE SECTION */

            create work_route.
/*J2DG*/    assign
               work_op = wr_op
               work_qty_to_move_next_op = 0 - following_op_input_que
               work_qty_to_process = work_qty_to_move_next_op - wr_qty_outque
               following_op_input_que = wr_qty_inque - work_qty_to_process.
         end.
/*H1J5*/ end. /* IF mfc_logical = yes */

/*H1J5*/ /* BEGIN OF ADDED CODE FOR 'Pulling WIP' LOGIC */
         else if (available mfc_ctrl and mfc_logical = no) then do:

            /* 1. IF INPUT Q QTY OF CURRENT OP IS GREATER OR EQUALS THE */
            /*    BACKFLUSH QTY, ONLY INPUT Q QTY NEEDS TO BE RELIEVED  */
            /*    AND THIS IS DONE BY REBKFLA.P AND REMOVEA.P WHICH ARE */
            /*    CALLED DIRECTLY BY REBKFL.P. HENCE WORK FILE NEED NOT */
            /*    BE CONSTRUCTED.                                       */
            /* 2. IF INPUT Q QTY OF THE CURRENT OP IS LESS THAN THE BKFL*/
            /*    QTY, WIP QTY SHOULD BE PULLED EFFECTIVELY FROM THE    */
            /*    INPUT Q AS WEEL AS INPUT/OUTPUT Q OF PRIOR NM OPS.    */
            /*    IF THE BACKFLUSH QTY IS NOT SATISFIED TILL INPUT Q OF */
            /*    THE LAST NM OPERATION IS REACHED, THEN THE LAST NM OP */
            /*    INPUT Q QTY SHOULD BE DRIVEN NEGATIVE.                */
            /* 3. IF BACKFLUSH QTY IS NEGATIVE AND MOVE TO NEXT OP IS   */
            /*    TRUE, CURRENT OP WILL HAVE INPUT Q INCREASE AND OUTPUT*/
            /*    Q DECREASE AND ALSO INPUT Q OF NEXT OP WILL DECREASE  */
            /*    AND OUTPUT Q OF CURRENT OP WILL INCREASE.             */
            /*    IF MOVE TO NEXT OP IS FALSE, THEN CURRENT OP WILL HAVE*/
            /*    ONLY THE INPUT Q INCREASED AND OUTPUT Q DECREASED.    */


/*N002*     if qty_proc < 0 then do: */
/*N002*        create work_route. */
/*N002*        assign work_op                  = wr_op */
/*N002*               work_qty_to_move_next_op = qty_proc */
/*N002*               work_qty_to_process      = qty_proc. */
/*N002*     end. /* IF qty_proc < 0 */ */
/*N002*     else do: */

               for each wr_route
/*J2DG*/          fields (wr_auto_lbr wr_lot wr_mch wr_milestone wr_op
/*J2DG*/                  wr_qty_inque wr_qty_outque wr_run wr_wkctr)
          no-lock
                  where wr_lot = cumwo_lot and wr_op < op
                  while not wr_milestone
                  break by wr_lot descending
                        by wr_op  descending:

/*N04H** BEGIN DELETE SECTION
 *                do trans:
 *                   {rewrsget.i &lot=wr_lot &op=wr_op}
 *                end.
 *N04H** END DELETE SECTION */

                  if following_op_input_que >= 0 then leave.

                  create work_route.

                  assign
                      work_op                  = wr_op
                      work_qty_to_move_next_op = 0 - following_op_input_que.

                  if work_qty_to_move_next_op - wr_qty_outque <= 0
                  then do:
                     assign work_qty_to_process = 0.
                     leave.
                  end. /* IF work_qty_to_move_next_op */

                  assign
                      work_qty_to_process    = work_qty_to_move_next_op -
                                               wr_qty_outque
                      following_op_input_que = wr_qty_inque -
                                               work_qty_to_process.

               end. /* for each wr_route */

/*N002**    end. /* IF qty_proc > 0 */  */

         end. /* IF available mfc_ctrl and mfc_logical = no */

/*H1J5*/ /* END OF ADDED SECTION */



         for each work_route no-lock,
         each wr_route
/*J2DG*/    fields (wr_auto_lbr wr_lot wr_mch wr_milestone wr_op
/*J2DG*/            wr_qty_inque wr_qty_outque wr_run wr_wkctr)
     no-lock
         where wr_lot = cumwo_lot and wr_op = work_op
         by work_op:

/*N04H** BEGIN DELETE SECTION
 *          do trans:
 *             {rewrsget.i &lot=wr_lot &op=wr_op}
 *          end.
 *N04H** END DELETE SECTION */

             dept = "".
/*J2DG**     find wc_mstr where wc_wkctr = wr_wkctr  */
/*J2DG**      and wc_mch = wr_mch no-lock no-error.  */
/*J2DG*/    for first wc_mstr
/*J2DG*/       fields (wc_dept wc_mch wc_wkctr)
/*J2DG*/       where wc_wkctr = wr_wkctr
/*J2DG*/       and wc_mch = wr_mch no-lock:
/*J2DG*/    end. /* FOR FIRST WC_MSTR */

            if available wc_mstr then dept = wc_dept.


            if work_qty_to_process <> 0 or work_qty_to_move_next_op <> 0 then do:
               {gprun.i ""reophist.p"" "(input trans_type,
               input wr_lot, input wr_op, input """",
               input wr_wkctr, input wr_mch, input dept, input shift,
               input eff_date,
               output ophist_recid)"}
/*GUI*/ if global-beam-me-up then undo, leave.

            end.


            /*REPORT LABOR AT THE STANDARD HOURS-PER*/
            if wr_auto_lbr then do:
/*J2DG*/       assign
                  extd_std_lbr_hours = work_qty_to_process * wr_run
                  earn_code          = "".

/*J2DG**       find first ea_mstr where ea_type = "1" no-lock no-error. */
/*J2DG*/       for first ea_mstr
/*J2DG*/          fields (ea_earn ea_type)
/*J2DG*/          where ea_type = "1" no-lock:
/*J2DG*/       end. /* FOR FIRST EA_MSTR */
               if available ea_mstr then earn_code = ea_earn.

               {gprun.i ""relbra.p"" "(input wr_lot, input wr_op,
               input wr_wkctr, input wr_mch, input dept, input extd_std_lbr_hours,
               input eff_date,
               input earn_code, input """", input true, input ophist_recid)"}
/*GUI*/ if global-beam-me-up then undo, leave.

            end.


            /*REGISTER THE QTY PROCESSED (REDUCE INQUE, INCREASE OUTQUE)*/
            {gprun.i ""rebkfla.p"" "(input wr_lot, input wr_op,
            input ophist_recid, input work_qty_to_process)"}
/*GUI*/ if global-beam-me-up then undo, leave.


/*N002 COMMENTED FOLLOWING SECTION
./*H1J5*/    /* removea.p SHOULD BE CALLED FOR NORMAL TRANSACTIONS INORDER  */
./*H1J5*/    /* TO MOVE THE QTY PROCESSED FROM THE CURRENT OPERATION'S      */
./*H1J5*/    /* OUTPUT QUEUE INTO THE INPUT QUEUE OF THE NEXT OPERATION.    */
./*H1J5*/    /* THIS SHOULD HOLD GOOD ONLY FOR THE NM OP's WHICH ARE        */
./*H1J5*/    /* PRECEDING THE CURRENT OPERATION (MILESTONE OR NON-MILESTONE)*/
./*H1J5*/    if (mfc_logical = yes) or
./*H1J5*/       (mfc_logical = no and qty_proc > 0)
./*H1J5*/    then do:
.*N002 END SECTION*/


               /*MOVE TO NEXT OPERATION*/
               {gprun.i ""removea.p""
             "(input wr_lot,
               input wr_op,
                           input eff_date,
               input ophist_recid,
               input work_qty_to_move_next_op)"}
/*GUI*/ if global-beam-me-up then undo, leave.


/*N002** /*H1J5*/    end. /* IF mfc_logical */  */

         end.
